package com.shen.jcbf.jdk8bf.optionalbf;

import java.util.Optional;
import java.util.stream.LongStream;

public class OptionalTest {

    public static void main(String[] args) {

        /*
        System.out.println(-1717986919 * 1);
        System.out.println(-1717986919 * 2);
        System.out.println(-1717986919 * 3);
        System.out.println(-1717986919 * 4);
        System.out.println(-1717986919 * 5);
        */

        System.out.println(858993459 * 5);
        System.out.println(1717986918 * 5);
        System.out.println(-1717986919 * 5);
        System.out.println(-858993460 * 5);
        System.out.println(-1 * 5);
        System.out.println(858993458 * 5);

        /*
        System.out.println(getInt(10));
        System.out.println(getInt(11));
        System.out.println(getInt(12));
        System.out.println(getInt(13));
        System.out.println(getInt(14));
        System.out.println(getInt(15));
        System.out.println(getInt(16));
        System.out.println(getInt(17));
        */
    }

    public static int getInt(int result){
        int a = (result - 3) % 5;
        if(a == 0){
            return (result - 3) / 5;
        }else {
            long s = (Integer.MAX_VALUE+1)*2;
            Long l = 0L;
            if (a == 1 || a == -4) {
                l = -(s/2 - result + 3) / 5;
            } else if (a == 2 || a == -3) {
                l = -(s - result + 3) / 5;
            } else if (a == 3 || a == -2) {
                l = (s + result - 3) / 5;
            } else if (a == 4 || a == -1) {
                l = (s/2 + result - 3) / 5;
            }
            return l.intValue();
        }
    }

    public static void test002(){
        long sum = LongStream.rangeClosed(0, 10L)
                .parallel()//并行流
                //.sequential()//串行流
                .reduce(0, Long::sum);
        System.out.println(sum);
    }
    public static void test001(){

        Optional<Employee> op = Optional.ofNullable(new Employee("jim","shanghai",9000));
        //Optional<Employee> op = Optional.ofNullable(null);

        //flatMap，返回的必须是Optional容器，进一步避免空指针异常
        Optional<Integer> optional = op.flatMap(e -> Optional.of(e.getSalary()));
        System.out.println(optional.orElse(10000));

    }

}

class Employee{
    private String name;
    private String adrress;
    private Integer salary;

    public Employee(String name, String adrress, Integer salary) {
        this.name = name;
        this.adrress = adrress;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdrress() {
        return adrress;
    }

    public void setAdrress(String adrress) {
        this.adrress = adrress;
    }

    public Integer getSalary() {
        return salary;
    }

    public void setSalary(Integer salary) {
        this.salary = salary;
    }
}
